<template>
  <div class='game_roll_putaway'>
    <Row type='flex'
         justify='center'
         style="padding:60px 100px">
      <Col style="width: 1200px;">
      <Steps :current="current">
        <Step title="完善商品信息"
              class="prev"></Step>
        <Step title="录入价格信息"
              class="prev"></Step>
        <Step title="完成"
              class="complate"></Step>
      </Steps>
      </Col>
    </Row>
    <div class="first-level content-style"
         v-show='current === 0'
         style="width: 850px">
      <div class="title">
        <p></p>
        <span>商品信息</span>
      </div>
      <Form inline
            ref="formValidate1"
            :model="formValidate1"
            :rules="ruleValidate1"
            :label-width="120"
            style="width: 850px;">
        <FormItem label="商品分类："
                  prop="productClassify">
          <Input v-model="formValidate1.productClassify"
                 placeholder="请输入"
                 style="width: 118px"
                 disabled></Input>
          <span style="color:#DCDEE2;margin: 0 8px">-</span>
          <Input v-model="formValidate1.productClassify2"
                 placeholder="请输入"
                 style="width: 118px"
                 disabled></Input>
          <!-- <span style="color: #2D8CF0;margin-left: 8px;cursor:pointer"
                @click='skipTwo'>编辑</span> -->
        </FormItem>
        <FormItem label="是否虚拟商品："
                  prop="goodsType"
                  :label-width='180'>
          <RadioGroup v-model="formValidate1.goodsType"
                      size="large">
            <Radio :label="1"
                   disabled>是</Radio>
            <Radio :label="0"
                   style="margin-left:50px"
                   disabled>否</Radio>
          </RadioGroup>
        </FormItem>
        <FormItem label="所属类型："
                  prop="relateType">
          <Select v-model="formValidate1.relateType"
                  @on-change="seletcType"
                  disabled
                  class='input-wid'
                  style="width: 260px">
            <Option v-for="(item, index) in involvedTypeList"
                    :value="item.typeCode"
                    :key="index">{{item.typeName}}</Option>
          </Select>
        </FormItem>
        <FormItem label="对应分类："
                  prop="matchClassify"
                  :label-width='180'>
          <Select v-model="formValidate1.matchClassify"
                  @on-change="seletcType1"
                  disabled
                  class='input-wid'
                  style='width:255px'>
            <Option v-for="(item, index) in matchClassifyList"
                    :value="item.typeCode"
                    :key="index">{{item.typeName}}</Option>
          </Select>
        </FormItem>
        <Row>
          <FormItem label="门店名称："
                    prop="shopId"
                    :rules="{required:true, message: '门店不能为空', trigger: 'blur'}">
            <!-- <Select v-model="formValidate1.shopId"
                    @on-change="seletcType2"
                    class='input-wid'
                    style='width:255px'>
              <Option v-for="(item, index) in shopList"
                      :value="item.typeCode"
                      :key="index">{{item.typeName}}</Option>
            </Select> -->
            <treeselect :options="options"
                        @select="selectListd"
                        class='input-wid'
                        :clearable="clearable"
                        :disable-branch-nodes="true"
                        style='width:255px'
                        :normalizer="normalizer"
                        noResultsText="未搜索符合的门店"
                        noOptionsText="门店为空"
                        placeholder="请选择门店"
                        v-model='formValidate1.shopId' />
          </FormItem>
        </Row>
        <FormItem label="商品标题："
                  prop="subTitle">
          <Input v-model="formValidate1.subTitle"
                 :maxlength="24"
                 @on-keyup="keyupsubTitle"
                 placeholder="请输入"
                 style="width: 255px"></Input>
        </FormItem>
        <FormItem label="商品名称："
                  prop="skuName"
                  :label-width='180'>
          <Input v-model="formValidate1.skuName"
                 :maxlength="12"
                 disabled
                 @on-keyup="keyupskuName"
                 placeholder="请输入"
                 style="width: 255px"></Input>
        </FormItem>
        <FormItem label="商品条码："
                  prop="barcode">
          <Input v-model="formValidate1.barcode"
                 :maxlength="13"
                 disabled
                 @on-keyup="keyup"
                 placeholder="请输入"
                 style="width: 255px"></Input>
        </FormItem>
        <FormItem label="商品编码："
                  prop="skuId"
                  :label-width='180'>
          <Input v-model="formValidate1.skuId"
                 placeholder="请输入"
                 disabled
                 style="width: 255px"></Input>
        </FormItem>
        <FormItem label="商品数量："
                  prop="goodsNum">
          <Input v-model="formValidate1.goodsNum"
                 disabled
                 placeholder="请输入"
                 style="width: 255px"></Input>
        </FormItem>
        <FormItem label="商品单位："
                  prop="goodsUnit"
                  :label-width='180'>
          <Select v-model="formValidate1.goodsUnit"
                  class='input-wid'
                  disabled
                  style='width:255px'>
            <Option v-for="(item, index) in goodsUnitList"
                    :value="item.value"
                    :key="index">{{item.label}}</Option>
          </Select>
        </FormItem>
        <FormItem label="游戏券局数："
                  prop="games">
          <Input v-model="formValidate1.games"
                 disabled
                 placeholder="请输入"
                 style="width: 255px"></Input><span style="padding:0 10px;">局</span>
        </FormItem>
        <FormItem label="销售形式："
                  prop="saleType"
                  :label-width='150'>
          <Select v-model="formValidate1.saleType"
                  class='input-wid'
                  disabled
                  style='width:255px'>
            <Option v-for="(item, index) in saleTypeList"
                    :value="item.value"
                    :key="index">{{item.label}}</Option>
          </Select>
        </FormItem>
        <Row>
          <FormItem label="上传图片："
                    prop="thumbnail">
            <upload-only :imgUrl.sync="formValidate1.thumbnail"></upload-only>
          </FormItem>
        </Row>
        <FormItem label="可选项目："
                  prop="project1"
                  class="tag-form"
                  style="width: 830px">
          <div class="tag-container"
               @click="selectProject">
            <Row type="flex"
                 style="width: 100%">
              <Col span="23">
              <Tag v-for="(item, index) in formValidate1.project1"
                   :key="index"
                   :name="index"
                   @click.native="selectProject"
                   closable
                   @on-close="deleteProject">{{ item.name }}</Tag>
              </Col>
              <Col span="1"
                   class="tag-flex">
              <Icon type="ios-search"
                    style="font-size: 18px" />
              </Col>
            </Row>
          </div>
          <!-- <Select v-model="formValidate1.project"
                  class='input-wid'
                  multiple
                  filterable
                  style='width:504px'>
            <Option v-for="(item, index) in projectList"
                    :value="item.id"
                    :key="index">{{item.value}}</Option>
          </Select> -->

        </FormItem>
        <Row v-if="formValidate1.matchClassify==='0201'">

          <FormItem label="项目设置："
                    prop="projectItems"
                    v-if="formValidate1.project1.length">
            <!-- <Form class="project-items"
                  ref="formDynamic"
                  :model="formDynamic"
                  :label-width="120"> -->
            <!-- <FormItem :label="item.machineName"
                        v-for="(item,idx) in formDynamic.list"
                        :key="idx"
                        :prop="'list.' + idx + '.value'"
                        class="project-items-le"> -->
            <div class="project-items">
              <div class="project-items-its"
                   v-for="(item,idx) in formDynamic.list"
                   :key="idx">
                <div class="project-items-items">{{item.machineName}}</div>
                <FormItem>
                  <Input style="width:96px;"
                         placeholder="请输入"
                         :maxlength="6"
                         @on-keyup="projectItemskeyup(item.count,item)"
                         @on-blur="projectItemsblur(item.count,item)"
                         v-model="item.count"></Input><span style="padding:0 10px;">局</span>
                </FormItem>
              </div>
            </div>
          </FormItem>
        </Row>
        <FormItem label="每天使用局数限制："
                  prop="dailyUseLimit"
                  v-if="formValidate1.matchClassify==='0202'"
                  :label-width='140'>
          <Input v-model="formValidate1.dailyUseLimit"
                 @on-keyup="dailyUsekeyup"
                 :maxlength="6"
                 @on-blur="dailyUseblur"
                 placeholder="请输入"
                 style="width: 255px"></Input><span style="padding:0 10px;">局</span>
        </FormItem>
        <Row>
          <FormItem label="有效期："
                    prop="validType">
            <Select v-model="formValidate1.validType"
                    class='input-wid'
                    @on-change="validTypeChange"
                    style='width:255px'>
              <Option v-for="(item, index) in timesList"
                      :value="item.id"
                      :key="index">{{item.value}}</Option>
            </Select>
          </FormItem>
          <FormItem label="时长："
                    prop="validDays"
                    v-if="formValidate1.validType==='2'"
                    :label-width='160'>
            <Input v-model="formValidate1.validDays"
                   @on-keyup="dailyUsekeyup"
                   :maxlength="6"
                   @on-blur="dailyUseblur"
                   placeholder="请输入"
                   style="width: 255px"></Input><span style="padding:0 10px;">天</span>
          </FormItem>
        </Row>
        <FormItem label="开始时间："
                  prop="validStart"
                  v-if="formValidate1.validType==='1'"
                  :label-width='120'>
          <DatePicker type="date"
                      v-model="formValidate1.validStart"
                      :options="validStartOptions"
                      @on-change="validStartChange"
                      placeholder="请选择"
                      style="width: 255px"></DatePicker>
        </FormItem>
        <FormItem label="结束时间："
                  prop="validEnd"
                  v-if="formValidate1.validType==='1'"
                  :label-width='180'>
          <DatePicker type="date"
                      v-model="formValidate1.validEnd"
                      @on-change="validEndChange"
                      :options="validEndOptions"
                      placeholder="请选择"
                      style="width: 255px"></DatePicker>
        </FormItem>
        <FormItem>
          <Button type="primary"
                  @click='submitOne'>下一步，录入价格信息</Button>
        </FormItem>
      </Form>
    </div>
    <div class="second-level content-style"
         v-show='current === 1'
         style="width: 910px;">
      <div class="title">
        <p></p>
        <span>价格信息</span>
      </div>
      <Form inline
            ref="formValidate2"
            :model="formValidate2"
            :rules="ruleValidate2"
            :label-width="95"
            style="width: 850px;">
        <Row>
          <FormItem label="销售渠道："
                    prop="qdName"
                    :label-width='85'>
            <Input v-model="formValidate2.qdName"
                   disabled
                   placeholder="请输入"
                   style="width: 255px"></Input>
          </FormItem>
        </Row>
        <FormItem label="商品价格："
                  prop="goodsPrice"
                  :label-width='85'>
          <Input v-model="formValidate2.goodsPrice"
                 disabled
                 placeholder="请输入"
                 style="width: 255px"></Input><span style="padding:0 10px;">元</span>
        </FormItem>
        <FormItem label="平台价格："
                  prop="ptPrice"
                  :label-width='150'>
          <Input v-model="formValidate2.ptPrice"
                 :maxlength="10"
                 @on-keyup="ptPricekeyup"
                 @on-blur="ptPriceblur"
                 placeholder="请输入"
                 style="width: 255px"></Input><span style="padding:0 10px;">元</span>
        </FormItem>
        <Row>
          <FormItem label="可售库存："
                    prop="inventory"
                    :rules="{required:unlimited?false:true,message:'请输入可售库存'}"
                    :label-width='85'>
            <Input v-model="formValidate2.inventory"
                   :disabled="unlimited"
                   :maxlength="6"
                   @on-keyup="dailyUsekeyup"
                   @on-blur="dailyUseblur"
                   placeholder="请输入"
                   style="width: 255px"></Input>
            <Checkbox v-model="unlimited"
                      style="padding-left:10px;">不限</Checkbox>
          </FormItem>
        </Row>
        <FormItem label="上架时间："
                  prop="listingAt"
                  :label-width='85'>
          <DatePicker type="datetime"
                      v-model="formValidate2.listingAt"
                      :options="listingTimeOptions"
                      :editable="editable"
                      @on-change="listingTimeChange"
                      placeholder="请选择"
                      style="width: 255px"></DatePicker>
        </FormItem>
        <FormItem label="下架时间："
                  prop="delistingAt"
                  :label-width='180'>
          <DatePicker type="datetime"
                      :editable="editable"
                      v-model="formValidate2.delistingAt"
                      :options="delistingTimeOptions"
                      @on-change="delistingTimeChange"
                      placeholder="请选择"
                      style="width: 255px"></DatePicker>
        </FormItem>
        <div class="title"
             style="margin-top:80px;">
          <p></p>
          <span>售卖规则</span>
        </div>
        <FormItem label="购买数量限制："
                  prop="limitUnit"
                  :label-width='120'>
          <Select v-model="formValidate2.limitUnit"
                  class='input-wid'
                  style='width:255px'>
            <Option v-for="(item, index) in limitUnitList"
                    :value="item.id"
                    :key="index">{{item.value}}</Option>
          </Select>
          <!-- <Input v-model="formValidate2.amountLimit"
                 placeholder="请输入"
                 style="width: 255px"></Input> -->
        </FormItem>
        <FormItem label="购买数量："
                  prop="amountLimit"
                  v-if="formValidate2.limitUnit!=='0'"
                  :label-width='150'>
          <Input v-model="formValidate2.amountLimit"
                 :maxlength="6"
                 @on-keyup="dailyUsekeyup"
                 @on-blur="dailyUseblur"
                 placeholder="请输入"
                 style="width: 255px"></Input><span style="padding:0 10px;">份</span>
        </FormItem>
        <Row>
          <FormItem>
            <div style="margin-top: 20px">
              <Button class="btn"
                      @click="skipTwo">上一步，完善商品信息</Button>
              <Button type="primary"
                      class="btn"
                      style="margin-left: 24px"
                      @click="submitTwo">下一步，完成商品上下架</Button>
            </div>
          </FormItem>
        </Row>
      </Form>
    </div>
    <div class="third-level content-style"
         style="width: 120px;text-align: center;padding-top: 50px"
         v-show='current === 2'>
      <div style="color: #18BE6B;">
        <Icon type="ios-checkmark-circle-outline"
              size='35' />
      </div>
      <h3 style="margin: 10px 0 50px 0">完成商品添加({{num}}秒)</h3>
      <Button type="primary"
              @click='skipList'>返回商品列表</Button>
    </div>
    <select-shop :checkdList="formValidate1.project1"
                 :dataTree="shopProjects"
                 :modalShow="modalShow"
                 @oncancel="selctshopCancel"
                 @selctshop="volumeSet"
                 v-if="modalShow">
    </select-shop>
  </div>
</template>
<script>
import UploadOnly from '@/view/components/upload-only/index.vue'
import { getDetailSysGoodsList, getMachineList, createChannelList } from '@/api/merchandise/index'
import { getOrgAllTree } from '@/api/system/org'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import SelectShop from '@/view/components/select-project/index.vue'
import dayjs from 'dayjs'
export default {
  name: 'game_roll_putaway',
  components: { UploadOnly, Treeselect, SelectShop },
  data () {
    return {
      current: 0,
      num: 3,
      timer: '',
      shopProjects: [],
      orgType: '',
      editable: false,
      normalizer (node) {
        return {
          id: node.id,
          label: node.orgName,
          children: node.childList && node.childList.length ? node.childList : undefined
        }
      },
      channelId: { '1': '2', '2': '1', '3': '4' },
      involvedTypeList: [],
      matchClassifyList: [], // 对应分类列表
      saleTypeList: [
        { value: 0, label: '打包销售' },
        { value: 1, label: '单独销售' }
      ],
      timesList: [
        { id: '2', value: '相对时间' },
        { id: '1', value: '时间段' }
      ],
      options: [], // 门店列表
      clearable: false,
      goodsUnitList: [
        { value: 0, label: '个' },
        { value: 1, label: '枚' },
        { value: 2, label: '份' }
      ],
      limitUnitList: [
        { id: '0', value: '无限制' },
        { id: '1', value: '天' },
        { id: '2', value: '周' },
        { id: '3', value: '月' },
        { id: '4', value: '年' }
      ],
      validStartOptions: {},
      validEndOptions: {
        disabledDate (date) {
          return date.valueOf() < Date.now() - 86400000
        }
      },
      listingTimeOptions: {},
      delistingTimeOptions: {
        disabledDate (date) {
          return date.valueOf() < Date.now() - 86400000
        }
      },
      projectList: [],
      subTrue: true,
      formValidate1: {
        shopId: null,
        productClassify: '', // 分类1
        productClassify2: '',
        goodsNum: 1,
        barcode: '',
        skuId: '',
        games: '',
        goodsType: '', // 是否虚拟商品
        relateType: '', // 所属类型
        matchClassify: '', // 对应分类
        subTitle: '', // 商品标题
        skuName: '', // 商品名称
        goodsUnit: '', // 商品单位
        saleType: '', // 销售形势
        thumbnail: '', // 上传图片
        project: '', // 可选项目
        limitUnit: '0',
        validType: '2',
        validDays: '',
        validStart: '',
        validEnd: '',
        project1: [],
        dailyUseLimit: '',
        projectItems: []
      },
      modalShow: false,
      formDynamic: {
        list: []
      },
      ruleValidate1: {
        productClassify: [{ required: true, message: '商品分类不能为空', trigger: 'blur' }],
        goodsType: { required: true, message: '请选择是否虚拟商品', trigger: 'change', type: 'number' },
        relateType: { required: true, message: '请选择所属类型', trigger: 'change' },
        matchClassify: { required: true, message: '请选择对应分类', trigger: 'change' },
        mealType: { required: true, message: '请选择套餐类型', trigger: 'change' },
        subTitle: { required: true, message: '商品标题不能为空', trigger: 'blur' },
        skuName: { required: true, message: '请输入商品名称', trigger: 'blur' },
        barcode: {
          required: true,
          trigger: 'blur',
          validator: (rule, value, callback) => {
            if (value) {
              // console.log('rr', value)
              callback()
            } else {
              callback(new Error('请输入商品条码'))
            }
          }
        },
        skuId: { required: true, message: '请输入商品编码', trigger: 'blur' },
        goodsNum: { required: true, message: '请输入商品数量', trigger: 'blur', type: 'number' },
        games: { required: true, message: '请输入游戏券局数', trigger: 'blur' },
        saleType: { required: true, message: '请选择销售形式' },
        goodsUnit: { required: true, message: '请选择商品单位' },
        thumbnail: { required: true, message: '请选择上传图片' },
        limitUnit: { required: true, message: '请选择购买数量限制', trigger: 'change' },
        amountLimit: { required: true, message: '请输入购买数量限制', trigger: 'blur' },
        validType: { required: true, message: '请选择有效期', trigger: 'change' },
        validDays: { required: true, message: '请输入有效期天数', trigger: 'blur' },
        dailyUseLimit: { required: true, message: '请输入每天使用局数限制', trigger: 'blur' },
        validStart: { required: true, message: '请选择开始有效期' },
        validEnd: { required: true, message: '请选择结束有效期' },
        project1: { required: true, message: '请选择项目' },
        projectItems: { required: true, message: '请选择项目设置' }
      },
      formValidate2: {
        qdName: ['', '一体机', '收银台', '微信商城'][this.$route.query.type], // 销售渠道
        goodsPrice: '',
        ptPrice: '',
        inventory: '',
        listingAt: '',
        delistingAt: '',
        amountLimit: '',
        limitUnit: '0'
      },
      ruleValidate2: {
        qdName: { required: true, message: '销售渠道不能为空', trigger: 'blur' },
        goodsPrice: { required: true, message: '商品价格不能为空', trigger: 'blur' },
        ptPrice: { required: true, message: '平台价格不能为空', trigger: 'blur' },
        listingAt: { required: true, message: '请选择上架时间' },
        delistingAt: {
          required: true,
          validator: (rule, value, callback) => {
            if (!new Date(this.formValidate2.delistingAt).getTime()) {
              callback(new Error('请选择下架时间'))
            } else if (new Date(this.formValidate2.delistingAt).getTime() < new Date(this.formValidate2.listingAt).getTime()) {
              callback(new Error('下架时间不能小于上架时间'))
            } else if (new Date(this.formValidate2.delistingAt).getTime() === new Date(this.formValidate2.listingAt).getTime()) {
              callback(new Error('下架时间不能等于上架时间'))
            } else if (new Date(this.formValidate2.delistingAt).getTime() < new Date().getTime()) {
              callback(new Error('下架时间要大于当前系统时间'))
            } else {
              callback()
            }
          }
        },
        limitUnit: { required: true, message: '请选择购买数量限制', trigger: 'change' },
        amountLimit: { required: true, message: '购买数量不能为空', trigger: 'blur' }
      },
      unlimited: false
    }
  },
  watch: {
    current (val) {
      if (val === 2) {
        this.num = 3
        this.timer = setInterval(() => {
          this.num--
          if (this.num === 0) {
            clearInterval(this.timer)
            this.handleReset()
          }
        }, 1000)
      }
    },
    'formValidate1.project1' (val) {
      if (val.length) {
        this.formValidate1.projectItems = []
        this.formDynamic.list = []
        val.forEach(ele => {
          let obj = { machineName: ele.name, machineId: ele.id, count: '1' }
          this.formValidate1.projectItems.push(obj)
        })
        this.formDynamic.list = this.formValidate1.projectItems
      }
    },
    unlimited (val) {
      if (val) {
        this.formValidate2.inventory = ''
        this.resetOneForm2('inventory')
      }
    }
  },
  computed: {
  },
  mounted () {
    this.getGoodsDetail()
  },
  methods: {
    selectListd (data) {
      this.formValidate1.shopId = data.id
      // this.resetOneForm('shopId')
      // this.$refs.formValidate1.validate((valid) => { })
      // this.$refs.formValidate1.validateField('shopId', (valid) => { })
      getMachineList({
        shopId: this.formValidate1.shopId
      }).then(res => {
        const result = res.data || {}
        if (result.status === 200) {
          this.formatShopProjects(result.data || [])
        } else {
          this.shopProjects = []
          this.formValidate1.project1 = []
          this.formDynamic.list = []
          this.$Message.error(`${result.error}`)
        }
      })
    },
    resetOneForm (prop) {
      this.$refs['formValidate1'].fields.forEach(e => {
        if (e.prop === prop) {
          e.resetField()
        }
      })
    },
    dailyUsekeyup () {
      if (this.formValidate1.dailyUseLimit.length === 1) {
        this.formValidate1.dailyUseLimit = this.formValidate1.dailyUseLimit.replace(/^[^\d]+/g, '')
      } else {
        this.formValidate1.dailyUseLimit = this.formValidate1.dailyUseLimit.replace(/^(0+)|[^\d]+/g, '')
      }
      this.formValidate1.validDays = this.formValidate1.validDays.replace(/^(0+)|[^\d]+/g, '')
      if (this.formValidate2.inventory.length === 1) {
        this.formValidate2.inventory = this.formValidate2.inventory.replace(/^[^\d]+/g, '')
      } if (this.formValidate2.inventory.length > 1) {
        this.formValidate2.inventory = this.formValidate2.inventory.replace(/^(0+)|[^\d]+/g, '')
      }
      this.formValidate2.amountLimit = this.formValidate2.amountLimit.replace(/^(0+)|[^\d]+/g, '')
    },
    dailyUseblur () {
      this.formValidate1.dailyUseLimit = this.formValidate1.dailyUseLimit.replace(/^[^\d]+/g, '')
      this.formValidate1.validDays = this.formValidate1.validDays.replace(/^[^\d]+/g, '')
      this.formValidate2.inventory = this.formValidate2.inventory.replace(/^[^\d]+/g, '')
      this.formValidate2.amountLimit = this.formValidate2.amountLimit.replace(/^(0+)|[^\d]+/g, '')
    },
    resetOneForm2 (prop) {
      this.$refs['formValidate2'].fields.forEach(e => {
        if (e.prop === prop) {
          e.resetField()
        }
      })
    },
    mapOrgAllTree (options, id) {
      if (options) {
        options.map(ele => {
          if (ele.id === id) {
            this.orgType = ele.orgType
          } else {
            this.mapOrgAllTree(options.childList, id)
          }
        })
      }
    },
    listingTimeChange (time) {
      this.delistingTimeOptions = {
        disabledDate (date) {
          if (!time) {
            return date.valueOf() < Date.now() - 86400000
          } else {
            if (new Date(time.split(' ')[0]).getTime() - 24 * 3600 * 1000 < Date.now() - 86400000) {
              return date.valueOf() < Date.now() - 86400000
            } else {
              return date.valueOf() < new Date(time.split(' ')[0]).getTime() - 24 * 3600 * 1000
            }
          }
        }
      }
    },
    delistingTimeChange (time) {
      this.listingTimeOptions = {
        disabledDate (date) {
          return date.valueOf() > new Date(time).getTime()
        }
      }
    },
    ptPricekeyup () {
      if (this.formValidate2.ptPrice !== '' && this.formValidate2.ptPrice.substring(0, 1) === '.') {
        this.formValidate2.ptPrice = ''
      }
      this.formValidate2.ptPrice = this.formValidate2.ptPrice.replace(/^0*(0\.|[1-9])/, '$1') // 粘贴不生效
      this.formValidate2.ptPrice = this.formValidate2.ptPrice.replace(/[^\d.]/g, '') // 清除“数字”和“.”以外的字符
      this.formValidate2.ptPrice = this.formValidate2.ptPrice.replace(/\.{2,}/g, '.') // 只保留第一个. 清除多余的
      this.formValidate2.ptPrice = this.formValidate2.ptPrice.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')
      this.formValidate2.ptPrice = this.formValidate2.ptPrice.replace(/^(-)*(\d+)\.(\d\d).*$/, '$1$2.$3') // 只能输入两个小数
      if (this.formValidate2.ptPrice.indexOf('.') < 0 && this.formValidate2.ptPrice !== '') { // 以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
        if (this.formValidate2.ptPrice.substring(0, 1) === '0' && this.formValidate2.ptPrice.length === 2) {
          this.formValidate2.ptPrice = this.formValidate2.ptPrice.substring(1, this.formValidate2.ptPrice.length)
        }
      }
      if (this.formValidate2.ptPrice > 9999999.99) {
        this.formValidate2.ptPrice = this.formValidate2.ptPrice.substring(0, 7)
      }
    },
    ptPriceblur () {
      this.formValidate2.ptPrice = this.formValidate2.ptPrice + ''
      this.formValidate2.ptPrice = this.formValidate2.ptPrice.replace(/[^\d.]/g, '')
      if (this.formValidate2.ptPrice === '') {
        this.formValidate2.ptPrice = ''
      } else if (this.formValidate2.ptPrice.indexOf('.') === -1) {
        this.formValidate2.ptPrice = this.formValidate2.ptPrice + '.00'
      } else if (this.formValidate2.ptPrice.indexOf('.')) {
        let ste = this.formValidate2.ptPrice.substring(this.formValidate2.ptPrice.indexOf('.') + 1)
        if (!ste) {
          this.formValidate2.ptPrice = this.formValidate2.ptPrice + '00'
        }
        if (ste.length === 1) {
          this.formValidate2.ptPrice = this.formValidate2.ptPrice + '0'
        } if (ste.length > 2) {
          this.formValidate2.ptPrice = this.formValidate2.ptPrice.substring(0, this.formValidate2.ptPrice.indexOf('.') + 3)
        }
      }
    },
    // 选择子项目
    selectProject () {
      if (!this.shopProjects.length) {
        this.$Message.error('该门店没有项目')
      } else {
        this.modalShow = true
      }
    },
    projectItemskeyup (val, item) {
      if (val.length === 1) {
        val = val.replace(/^[^\d]+/g, '')
        this.$set(item, 'count', val.replace(/^[^\d]+/g, ''))
      } else {
        this.$set(item, 'count', val.replace(/^(0+)|[^\d]+/g, ''))
      }
    },
    projectItemsblur (val, item) {
      val = val.replace(/^[^\d]+/g, '')
      this.$set(item, 'count', val || '0')
    },
    validTypeChange () {
      this.resetOneForm('validStart')
      this.resetOneForm('validEnd')
      this.resetOneForm('validDays')
      this.formValidate1.validStart = ''
      this.formValidate1.validEnd = ''
      this.formValidate1.validDays = ''
    },
    validStartChange (time) {
      this.validEndOptions = {
        disabledDate (date) {
          if (!time) {
            return date.valueOf() < Date.now() - 86400000
          } else {
            if (new Date(time).getTime() - 24 * 60 * 60 * 1000 < Date.now() - 86400000) {
              return date.valueOf() < Date.now() - 86400000
            } else {
              return date.valueOf() < new Date(time).getTime() - 24 * 60 * 60 * 1000
            }
          }
        }
      }
    },
    validEndChange (time) {
      this.validStartOptions = {
        disabledDate (date) {
          return date.valueOf() > new Date(time).getTime()
        }
      }
    },
    // 获取门店列表
    getShopList (id) {
      getOrgAllTree({
        'merchantId': this.$store.state.user.merchantId,
        'orgType': 1,
        status: 1,
        perms: 'moms:product:gamecouponview',
        id: this.$store.state.user.orgId
        // perms: "moms:report:groupbuyanalytics"
      }).then(res => {
        if (res.data.status === 200) {
          this.options = [res.data.data]
          // console.log(this.orgType)
          this.formValidate1.shopId = id
          this.mapOrgAllTree(this.options, id)
          if (this.orgType) {
            getMachineList({
              shopId: id
            }).then(resd => {
              const result = resd.data || {}
              if (result.status === 200) {
                this.formatShopProjects(result.data || [])
              } else {
                this.$Message.error(`${result.error}`)
              }
            })
          }
        } else {
          this.$Message.error(`${res.data.error}`)
        }
      })
    },
    formatShopProjects (projects) {
      // console.log('ss', projects)
      this.shopProjects = projects.map(item => {
        item.orgName = item.machineCategoryName
        item.id = item.machineCategoryId
        item.orgType = 0
        item.childList = item.machineDTOs.map(childItem => {
          childItem.id = childItem.machineId
          childItem.orgName = childItem.name
          childItem.parentId = item.machineCategoryId
          childItem.orgType = 1
          childItem.childList = []
          return childItem
        })
        return item
      })
      // console.log('dd', this.shopProjects)
    },
    seletcType () {

    },
    // 对应分类1
    seletcType1 () {

    },
    // 门店列表
    seletcType2 () {

    },
    // 商品标题
    keyupsubTitle () {

    },
    // 商品名称
    keyupskuName () {

    },
    selctshopCancel () {
      this.modalShow = false
    },
    volumeSet (val) {
      this.modalShow = false
      this.resetOneForm('project1')
      this.formValidate1.project1 = val
    },

    // 商品条码
    keyup () {

    },
    skipTwo () {
      this.current--
    },
    // 返回商品列表
    skipList () {
      clearInterval(this.timer)
      this.handleReset()
    },
    handleReset () {
      this.$store.commit('closeTag', this.$route)
      // this.$store.commit('setTagNavList', this.$store.state.app.tagNavList.filter(item => !routeEqual(this.$route, item)))
      if (this.$store.state.app.tagNavList[this.$store.state.app.tagNavList.length - 1].name !== 'game_roll_aio') {
        this.$nextTick(() => {
          this.$router.push({
            name: 'game_roll_aio',
            query: { id: this.$route.query.id, sysId: this.$route.query.sysId, type: this.$route.query.type, sysGoodsId: this.$route.query.sysGoodsId }
          })
        })
      }
    },
    // 第一步提交
    submitOne () {
      this.$refs.formValidate1.validate((val) => {
        if (val) {
          if (this.formValidate1.matchClassify === '0201') {
            let counter = 0
            this.formDynamic.list.map(ele => {
              counter += Number(ele.count)
            })
            if (counter + '' !== this.formValidate1.games) {
              this.$Message.error('机台局数总和必须与游戏券局数相等')
            } else {
              if (this.current === 2) {
                this.current = 0
              } else {
                this.current += 1
              }
            }
          } else {
            if (this.current === 2) {
              this.current = 0
            } else {
              this.current += 1
            }
          }
        }
      })
    },
    // 获取商品详情
    getGoodsDetail () {
      getDetailSysGoodsList({
        merchantId: this.$store.state.user.merchantId,
        sysGoodsId: this.$route.query.sysGoodsId
      }).then(res => {
        if (res.data.status === 200) {
          let result = (res.data.data || {}).goods
          // console.log(result)
          this.$refs.formValidate1.resetFields()
          this.involvedTypeList = [result.goodsKindList[0]]
          this.matchClassifyList = [result.goodsKindList[1]]
          this.typeLen = result.goodsKindList.length
          this.formValidate1.involvedType = result.goodsKindList[0].typeCode
          this.formValidate1.productClassify = res.data.data.parentSysCategoryName
          this.formValidate1.productClassify2 = res.data.data.sysCategoryName
          this.formValidate1.goodsType = result.goodsType
          this.formValidate1.relateType = result.goodsKindList[0].typeCode
          this.formValidate1.matchClassify = result.goodsKindList[1].typeCode
          this.formValidate1.saleType = result.gameCouponExtra ? result.gameCouponExtra.saleType : ''
          this.formValidate1.subTitle = result.subTitle
          this.formValidate1.skuName = result.skuName
          this.formValidate1.barcode = result.barcode
          this.formValidate1.skuId = result.skuId
          this.formValidate1.games = result.gameCouponTimesConfig.configValue
          this.formValidate1.goodsUnit = result.goodsUnit
          this.formValidate1.thumbnail = result.thumbnail
          this.formValidate2.goodsPrice = result.gameCouponPriceConfig.configValue
          this.formValidate2.ptPrice = result.hasOwnProperty('goodsPrices') ? goodsPrices[0].amount : result.gameCouponPriceConfig.configValue
          this.getShopList(res.data.data.shopId)
        } else {
          this.$Message.error(`${res.data.error}`)
        }
      })
    },
    deleteProject (event, index) {
      this.formValidate1.project1.splice(index, 1)
      this.formDynamic.list.splice(index, 1)
      // this.formDynamic.list = this.formValidate1.projectItems
    },
    // 第二步提交
    submitTwo () {
      this.$refs.formValidate2.validate((val) => {
        // console.log('ss', val)
        if (val) {
          let dataParmas = []
          if (this.formValidate1.matchClassify === '0201') {
            dataParmas = [{
              limitUnit: this.formValidate2.limitUnit,
              amountLimit: this.formValidate2.amountLimit,
              validType: this.formValidate1.validType,
              validDays: this.formValidate1.validDays,
              validStart: this.formValidate1.validStart ? dayjs(this.formValidate1.validStart).format('YYYY-MM-DD 00:00:00') : '',
              validEnd: this.formValidate1.validEnd ? dayjs(this.formValidate1.validEnd).format('YYYY-MM-DD 00:00:00') : '',
              dailyUseLimit: this.formValidate1.dailyUseLimit,
              machineDetail: this.formDynamic.list
            }]
          } else {
            dataParmas = [{
              limitUnit: this.formValidate2.limitUnit,
              amountLimit: this.formValidate2.amountLimit,
              validType: this.formValidate1.validType,
              validDays: this.formValidate1.validDays,
              validStart: this.formValidate1.validStart ? dayjs(this.formValidate1.validStart).format('YYYY-MM-DD 00:00:00') : '',
              validEnd: this.formValidate1.validEnd ? dayjs(this.formValidate1.validEnd).format('YYYY-MM-DD 00:00:00') : '',
              dailyUseLimit: this.formValidate1.dailyUseLimit,
              machineDetail: this.formDynamic.list.map(ele => {
                return {
                  machineName: ele.machineName,
                  machineId: ele.machineId
                }
              })
            }]
          }
          if (this.subTrue) {
            createChannelList({
              merchantId: this.$store.state.user.merchantId,
              channelId: this.channelId[this.$route.query.type],
              shopId: this.formValidate1.shopId,
              sysGoodsId: this.$route.query.sysGoodsId,
              sysId: 'xsxt',
              title: this.formValidate1.subTitle,
              thumbnail: this.formValidate1.thumbnail,
              listingAt: dayjs(this.formValidate2.listingAt).format('YYYY-MM-DD HH:mm:ss'),
              delistingAt: dayjs(this.formValidate2.delistingAt).format('YYYY-MM-DD HH:mm:ss'),
              creator: this.$store.state.user.userId,
              creatorName: this.$store.state.user.userName,
              inventory: this.unlimited ? '-1' : this.formValidate2.inventory,
              goodsPrices: [
                { priceType: 0, priceCategory: 1, amount: this.formValidate2.ptPrice }
              ],
              subChannelGameCoupons: dataParmas
            }).then(res => {
              if (res.data.status === 200) {
                this.$Message.success('上架成功')
                setTimeout(() => {
                  this.subTrue = true
                }, 1000)
                if (this.current === 2) {
                  this.current = 0
                } else {
                  this.current += 1
                }
              } else {
                setTimeout(() => {
                  this.subTrue = true
                }, 1000)
                this.$Message.error(`${res.data.error}`)
              }
            })
          }
        }
      })
    }
  }
}
</script>
<style lang="less">
.game_roll_putaway {
  .tag-form {
    .ivu-form-item-content {
      width: 600px;
    }
    .tag-container {
      display: flex;
      flex-wrap: wrap;
      min-height: 32px;
      padding: 4px 7px;
      min-width: 280px;
      border: 1px solid #dcdee2;
      border-radius: 4px;
      cursor: pointer;
      text-align: left;
      &.setting {
        background: #f8f8f9;
        padding: 10px 30px 0 10px;
        .ivu-form {
          display: flex;
          align-items: center;
          flex-wrap: wrap;
          width: 100%;
          input,
          .ivu-form-item-content {
            display: flex;
            justify-content: space-between;
            align-items: center;
            width: 80px;
          }
          .ivu-form-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 10px;
            margin-right: 50px;
            &:nth-child(3n) {
              margin-right: 0;
            }
          }
          .ivu-form-item-label {
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
          }
        }
      }
    }
    .tag-flex {
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
  .prev {
    width: 45% !important;
  }
  .complate {
    width: 10% !important;
  }
  .content-style {
    margin: 0 auto !important;
  }
  .title {
    display: flex;
    margin-bottom: 30px;
    p {
      width: 8px;
      height: 20px;
      background: #2d8cf0;
      margin-right: 10px;
    }
  }
  .project-items {
    width: 745px;
    background: #f8f8f9;
    border: 1px solid #e9e9e9;
    padding: 20px 10px;
    border-radius: 3px;
    .project-items-its {
      width: 250px;
      margin-bottom: 10px;
      display: inline-block;
      .project-items-items {
        display: inline-block;
        width: 100px;
      }
    }
  }
}
</style>
